package com.xafc.demo.framework.result;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;

import java.util.List;

/**
 * 分页数据返回
 */
@Data
public class PageResult<T> {
    private Long code;

    private Long count;

    private List<T> data;

    /**
     * 合计行数据
     */
    private T totalRow;

    private String msg;


    public static <T> PageResult<T> success(Page<T> page) {
        PageResult<T> result = new PageResult<>();
        result.setData(page.getRecords());
        result.setCount(page.getTotal());
        result.setCode(0L);
        return result;
    }


    public static <T> PageResult<T> success(List<T> page, long count) {
        final PageResult<T> result = new PageResult<>();
        result.setData(page);
        result.setCount(count);
        result.setCode(0L);
        return result;
    }
}
